gdb/garmin_tables: Add basic code for new color concept.
authoroliskoli <oliskoli>
Sun, 17 Aug 2008 21:07:43 +0000 (21:07 +0000)
committeroliskoli <oliskoli>
Sun, 17 Aug 2008 21:07:43 +0000 (21:07 +0000)
garmin_tables.c
garmin_tables.h
gdb.c

index 11a064ad05f4d6a72a39a7b39f1391a729ea6e2c..7524bb97cd3ce91311906f082de1d26d9c619987 100644 (file)
@@ -629,7 +629,7 @@ typedef struct {
 } datum_mapping_t;
 
 /* will be continued (when requested) */       
-datum_mapping_t gt_mps_datum_names[] = 
+static datum_mapping_t gt_mps_datum_names[] = 
 {
        { "Alaska-NAD27",       "NAD27 Alaska" },
        { "Bahamas NAD27",      "NAD27 Bahamas" },
@@ -646,6 +646,36 @@ datum_mapping_t gt_mps_datum_names[] =
        { NULL, NULL }
 };
 
+typedef struct garmin_color_s {
+       char *name;
+       gbint32 rgb;
+} garmin_color_t;
+
+static garmin_color_t gt_colors[] =
+{
+       { "Unknown",            unknown_color },
+       { "Black",              0x000000 },
+       { "DarkRed",            0x00008B },
+       { "DarkGreen",          0x006400 },
+       { "DarkYellow",         0x008B8B },
+       { "DarkBlue",           0x8B0000 },
+       { "DarkMagenta",        0x8B008B },
+       { "DarkCyan",           0x8B8B00 },
+       { "LightGray",          0xD3D3D3 },
+       { "DarkGray",           0xA9A9A9 },
+       { "Red",                0x0000FF },
+       { "Green",              0x008000 },
+       { "Yellow",             0x00FFFF },
+       { "Blue",               0xFF0000 },
+       { "Magenta",            0xFF00FF },
+       { "Cyan",               0xFFFF00 },
+       { "White",              0xFFFFFF },
+       { "Transparent",        unknown_color }, /* Currently not handled */
+       { NULL }
+};
+
+#define GT_COLORS_CT ((sizeof(gt_colors) / sizeof(gt_colors[0])) - 1)
+
 unsigned char
 gt_switch_display_mode_value(const unsigned char display_mode, const int protoid, const char device)
 {
@@ -954,6 +984,58 @@ gt_lookup_datum_index(const char *datum_str, const char *module)
        return result;
 }
 
+gbuint32
+gt_color_value(const int garmin_index)
+{
+       if ((garmin_index >= 0) && (garmin_index < GT_COLORS_CT))
+               return gt_colors[garmin_index].rgb;
+       else
+               return unknown_color;   /* -1 */
+}
+
+gbuint32
+gt_color_value_by_name(const char *name)
+{
+       int i;
+
+       for (i = 0; i < GT_COLORS_CT; i++)
+               if (case_ignore_strcmp(gt_colors[i].name, name) == 0)
+                       return gt_colors[i].rgb;
+
+       return gt_colors[0].rgb;
+}
+
+int
+gt_color_index_by_name(const char *name)
+{
+       int i;
+
+       for (i = 0; i < GT_COLORS_CT; i++)
+               if (case_ignore_strcmp(name, gt_colors[i].name) == 0) return i;
+
+       return 0; /* unknown */
+}
+
+int
+gt_color_index_by_rgb(const int rgb)
+{
+       int i;
+
+       for (i = 0; i < GT_COLORS_CT; i++)
+               if (rgb == gt_colors[i].rgb) return i;
+
+       return 0; /* unknown */
+}
+
+const char *
+gt_color_name(const int garmin_index)
+{
+       if ((garmin_index >= 0) && (garmin_index < GT_COLORS_CT))
+               return gt_colors[garmin_index].name;
+       else
+               return gt_colors[0].name;
+}
+
 #if MAKE_TABLE
 
 /*
index c846c94c57d49ede593fb5e66b8bc81578c69c4a..d23ede9cc471ece810f96ae1d7d452588a4656f1 100644 (file)
@@ -96,5 +96,10 @@ grid_type gt_lookup_grid_type(const char *grid_name, const char *module);
 char *gt_get_mps_grid_longname(const grid_type grid, const char *module);
 int gt_lookup_datum_index(const char *datum_str, const char *module);
 char *gt_get_mps_datum_name(const int datum_index);
+gbuint32 gt_color_value(const int garmin_index);
+gbuint32 gt_color_value_by_name(const char *name);
+int gt_color_index_by_name(const char *name);
+int gt_color_index_by_rgb(const int rgb);
+const char *gt_color_name(const int garmin_index);
 
 #endif
diff --git a/gdb.c b/gdb.c
index 7893dceec0e0fb48bc24513d450ab722de3340b4..4affaa1babf755161a1eb1a35ff990807ae04027 100644 (file)
--- a/gdb.c
+++ b/gdb.c
@@ -59,6 +59,7 @@
            2007/07/07: Better support for new fields since V3 (postal code/street address/instruction)
            2008/01/09: Fix handling of option category (cat)
            2008/04/27: Add zero to checklist of "unknown bytes"
+           2008/08/17: Add concept of route/track line colors
 */
 
 #include <stdio.h>
 
 /*******************************************************************************/
 
-/* static char gdb_release[] = "$Revision: 1.65 $"; */
-static char gdb_release_date[] = "$Date: 2008/05/04 23:09:08 $";
+/* static char gdb_release[] = "$Revision: 1.66 $"; */
+static char gdb_release_date[] = "$Date: 2008/08/17 21:07:43 $";
 
 static gbfile *fin, *fout;
 static int gdb_ver, gdb_category, gdb_via, gdb_roadbook;
@@ -531,7 +532,7 @@ read_waypoint(gt_waypt_classes_e *waypt_class_out)
        }
        GMSD_SET(display, display);
        
-       FREAD_i32;                              /* color/colour !not implemented! */
+       FREAD_i32;                              /* color !not implemented! */
        icon = FREAD_i32;
        GMSD_SET(icon, icon);                   /* icon */
        FREAD_STR(buf);                         /* city */
@@ -685,7 +686,8 @@ read_route(void)
        int points, warnings, links, i;
        char buf[128];
        bounds bounds;
-       
+       int color_idx;
+
        rte_ct++;
        warnings = 0;
 
@@ -859,7 +861,8 @@ read_route(void)
        else {
                rte->rte_url = gdb_fread_strlist();
                
-               FREAD(buf, 4);                  /* ?????????????????????????????????? */
+               color_idx = FREAD_i32;
+               rte->line_color.bbggrr = gt_color_value(color_idx);
                FREAD(buf, 1);                  /* ?????????????????????????????????? */
 
                rte->rte_desc = FREAD_CSTR;
@@ -885,7 +888,8 @@ read_track(void)
        route_head *res;
        int points, index;
        char dummy;
-       
+       int color_idx;
+
        trk_ct++;
 
        res = route_head_alloc();
@@ -893,8 +897,9 @@ read_track(void)
 //     res->rte_num = trk_ct;
 
        FREAD(&dummy, 1);               /* display - 1 byte */
-       FREAD_i32;                      /* color -   1 dword */
-       
+       color_idx = FREAD_i32;          /* color -  1 dword */
+       res->line_color.bbggrr = gt_color_value(color_idx);
+
        points = FREAD_i32;
        
        for (index = 0; index < points; index++)
@@ -1210,7 +1215,7 @@ write_waypoint(
                FWRITE_CSTR(wpt->description);
        FWRITE_DBL(WAYPT_GET(wpt, proximity, unknown_alt), unknown_alt);        /* proximity */
        FWRITE_i32(display);                    /* display */
-       FWRITE_i32(0);                          /* color (colour) */
+       FWRITE_i32(0);                          /* color */
        FWRITE_i32(icon);                       /* icon */
        FWRITE_CSTR(GMSD_GET(city, ""));        /* city */
        FWRITE_CSTR(GMSD_GET(state, ""));       /* state */
@@ -1412,7 +1417,8 @@ write_route(const route_head *rte, const char *rte_name)
        }
        else /* if (gdb_ver >= GDB_VER_3) */ {
                FWRITE_CSTR_LIST(rte->rte_url);
-               FWRITE_i32(0x0E);       /* color ??? */
+               /* "Magenta" (14) is MapSource default */
+               FWRITE_i32( (rte->line_color.bbggrr < 0) ? 14 : gt_color_index_by_rgb(rte->line_color.bbggrr) );
                FWRITE_C(0);
                FWRITE_CSTR(rte->rte_desc);
        }
@@ -1426,7 +1432,8 @@ write_track(const route_head *trk, const char *trk_name)
        
        FWRITE_CSTR(trk_name);
        FWRITE_C(0);
-       FWRITE_i32(0);
+       /* "Unknown" (0) is MapSource default */
+       FWRITE_i32(gt_color_index_by_rgb(trk->line_color.bbggrr));
 
        FWRITE_i32(points);     /* total number of waypoints in waypoint list */